package com.jiayang.hhotel.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.adapter.BuildNoAdapter;
import com.jiayang.hhotel.bean.BuildNoModel;
import com.jiayang.hhotel.presenter.PBuildNo;
import com.jiayang.hhotel.util.StatusBarUtils;
import com.jiayang.hhotel.view.StateView;

import cn.droidlover.xdroidmvp.mvp.XActivity;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xrecyclerview.XRecyclerContentLayout;
import cn.droidlover.xrecyclerview.XRecyclerView;

/**
 * Created by Administrator on 2017/5/3 0003.
 * 楼号设置
 */

public class BuildingNoActivity extends XActivity <PBuildNo>{

    private XRecyclerContentLayout build_no_content;

    private StateView errorView;
    private BuildNoAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        StatusBarUtils.setWindowStatusBarColor(this,R.color.bg);
        super.onCreate(savedInstanceState);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            Window window = getWindow();
//            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
//                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            window.setStatusBarColor(Color.TRANSPARENT);
//            window.setNavigationBarColor(Color.TRANSPARENT);
//        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initAdapter();
        //获取P数据
        getP().loadData(1,new Long("237812631123"),"0","RmStyle","",0);
        //setData(1);
    }
    private void initAdapter(){
        build_no_content=(XRecyclerContentLayout)findViewById(R.id.build_no_content);
        adapter=new BuildNoAdapter(context);
        build_no_content.getRecyclerView().verticalLayoutManager(context);
        build_no_content.getRecyclerView().setAdapter(adapter);
        build_no_content.getRecyclerView().setOnRefreshAndLoadMoreListener(new XRecyclerView.OnRefreshAndLoadMoreListener() {
            @Override
            public void onRefresh() {
                //getP().loadData(1);
            }

            @Override
            public void onLoadMore(int page) {
                //getP().loadData(page);
            }
        });
        if (errorView == null) {
            errorView = new StateView(context);
        }
        build_no_content.errorView(errorView);
        build_no_content.loadingView(View.inflate(context, R.layout.view_loading, null));

        build_no_content.getRecyclerView().useDefLoadMoreView();
    }
    public void setData(int page,BuildNoModel model){

//        for(int i=0;i<10;i++){
//            BuildNoModel.item item=new BuildNoModel.item();
//            item.setBuildNoImgUrl("http://img15.3lian.com/2015/c1/83/d/29.jpg");
//            item.setBuildNo("00"+i);
//            item.setBuildNoChi("中国");
//            item.setBuildNoEng("english");
//            list.add(item);
//        }

        if(page>1){
            adapter.addData(model.getBldgList());
        }else{
            adapter.setData(model.getBldgList());
        }
        build_no_content.getRecyclerView().setPage(page,10);
        if (adapter.getItemCount() < 1) {
            build_no_content.showEmpty();
            return;
        }
    }
    public void show(int page,BuildNoModel model){
        //errorView.setMsg(OK);
        getvDelegate().toastShort("成功");
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_buildingno;
    }

    @Override
    public PBuildNo newP() {
        return new PBuildNo();
    }

    public void showError(NetError error) {
        if (error != null) {
            switch (error.getType()) {
                case NetError.ParseError:
                    errorView.setMsg("数据解析异常");
                    break;

                case NetError.AuthError:
                    errorView.setMsg("身份验证异常");
                    break;

                case NetError.BusinessError:
                    errorView.setMsg("业务异常");
                    break;

                case NetError.NoConnectError:
                    errorView.setMsg("网络无连接");
                    break;

                case NetError.NoDataError:
                    errorView.setMsg("数据为空");
                    break;

                case NetError.OtherError:
                    errorView.setMsg("其他异常");
                    break;
            }
            build_no_content.showError();
        }
    }
}
